Introduce a separate "hide_if_empty" property for empty menu handling.
authorMatthias Clasen <maclas@gmx.de>
Wed, 1 Oct 2003 19:07:36 +0000 (19:07 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 1 Oct 2003 19:07:36 +0000 (19:07 +0000)
2003-10-01  Matthias Clasen  <maclas@gmx.de>

* gtk/gtkaction.c (gtk_action_class_init):
(gtk_action_[gs]et_property): Introduce a separate
"hide_if_empty" property for empty menu handling.
(_gtk_action_sync_menu_visible): ...and use it here.

* tests/testmerge.c (main): ...and here.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkaction.c
tests/testmerge.c

index 9a523a9e548c04fbf73929ec82b7183802c4d84c..01b82568cb26de17cf14ea8176ca2af831e90d78 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2003-10-01  Matthias Clasen  <maclas@gmx.de>
 
+       * gtk/gtkaction.c (gtk_action_class_init): 
+       (gtk_action_[gs]et_property): Introduce a separate
+       "hide_if_empty" property for empty menu handling.
+       (_gtk_action_sync_menu_visible): ...and use it here.
+
+       * tests/testmerge.c (main): ...and here.
+
        * gtk/gtktoolitem.c (gtk_tool_item_class_init): Fix signal doc 
        comments to pacify gtk-doc.
 
index 9a523a9e548c04fbf73929ec82b7183802c4d84c..01b82568cb26de17cf14ea8176ca2af831e90d78 100644 (file)
@@ -1,5 +1,12 @@
 2003-10-01  Matthias Clasen  <maclas@gmx.de>
 
+       * gtk/gtkaction.c (gtk_action_class_init): 
+       (gtk_action_[gs]et_property): Introduce a separate
+       "hide_if_empty" property for empty menu handling.
+       (_gtk_action_sync_menu_visible): ...and use it here.
+
+       * tests/testmerge.c (main): ...and here.
+
        * gtk/gtktoolitem.c (gtk_tool_item_class_init): Fix signal doc 
        comments to pacify gtk-doc.
 
index 9a523a9e548c04fbf73929ec82b7183802c4d84c..01b82568cb26de17cf14ea8176ca2af831e90d78 100644 (file)
@@ -1,5 +1,12 @@
 2003-10-01  Matthias Clasen  <maclas@gmx.de>
 
+       * gtk/gtkaction.c (gtk_action_class_init): 
+       (gtk_action_[gs]et_property): Introduce a separate
+       "hide_if_empty" property for empty menu handling.
+       (_gtk_action_sync_menu_visible): ...and use it here.
+
+       * tests/testmerge.c (main): ...and here.
+
        * gtk/gtktoolitem.c (gtk_tool_item_class_init): Fix signal doc 
        comments to pacify gtk-doc.
 
index 9a523a9e548c04fbf73929ec82b7183802c4d84c..01b82568cb26de17cf14ea8176ca2af831e90d78 100644 (file)
@@ -1,5 +1,12 @@
 2003-10-01  Matthias Clasen  <maclas@gmx.de>
 
+       * gtk/gtkaction.c (gtk_action_class_init): 
+       (gtk_action_[gs]et_property): Introduce a separate
+       "hide_if_empty" property for empty menu handling.
+       (_gtk_action_sync_menu_visible): ...and use it here.
+
+       * tests/testmerge.c (main): ...and here.
+
        * gtk/gtktoolitem.c (gtk_tool_item_class_init): Fix signal doc 
        comments to pacify gtk-doc.
 
index 9a523a9e548c04fbf73929ec82b7183802c4d84c..01b82568cb26de17cf14ea8176ca2af831e90d78 100644 (file)
@@ -1,5 +1,12 @@
 2003-10-01  Matthias Clasen  <maclas@gmx.de>
 
+       * gtk/gtkaction.c (gtk_action_class_init): 
+       (gtk_action_[gs]et_property): Introduce a separate
+       "hide_if_empty" property for empty menu handling.
+       (_gtk_action_sync_menu_visible): ...and use it here.
+
+       * tests/testmerge.c (main): ...and here.
+
        * gtk/gtktoolitem.c (gtk_tool_item_class_init): Fix signal doc 
        comments to pacify gtk-doc.
 
index 33bacf738af5ee0ee93760bc5c53a248bfa5c6dd..28694bab2f9d6319bbba8c6ef9660217daa2ffa5 100644 (file)
@@ -60,6 +60,7 @@ struct _GtkActionPrivate
   guint label_set       : 1; /* these two used so we can set label */
   guint short_label_set : 1; /* based on stock id */
   guint is_important    : 1;
+  guint hide_if_empty   : 1;
 
   /* accelerator */
   guint          accel_count;
@@ -88,6 +89,7 @@ enum
   PROP_TOOLTIP,
   PROP_STOCK_ID,
   PROP_IS_IMPORTANT,
+  PROP_HIDE_IF_EMPTY,
   PROP_SENSITIVE,
   PROP_VISIBLE
 };
@@ -217,9 +219,16 @@ gtk_action_class_init (GtkActionClass *klass)
                                   PROP_IS_IMPORTANT,
                                   g_param_spec_boolean ("is_important",
                                                         _("Is important"),
-                                                        _("Whether the action is considered important. When TRUE, toolitem proxies for this action show text in GTK_TOOLBAR_BOTH_HORIZ mode, and empty menu proxies for this action are not hidden."),
+                                                        _("Whether the action is considered important. When TRUE, toolitem proxies for this action show text in GTK_TOOLBAR_BOTH_HORIZ mode."),
                                                         FALSE,
                                                         G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+                                  PROP_HIDE_IF_EMPTY,
+                                  g_param_spec_boolean ("hide_if_empty",
+                                                        _("Hide if empty"),
+                                                        _("When TRUE, empty menu proxies for this action are hidden."),
+                                                        TRUE,
+                                                        G_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_SENSITIVE,
                                   g_param_spec_boolean ("sensitive",
@@ -307,6 +316,7 @@ gtk_action_init (GtkAction *action)
   action->private_data->tooltip = NULL;
   action->private_data->stock_id = NULL;
   action->private_data->is_important = FALSE;
+  action->private_data->hide_if_empty = TRUE;
 
   action->private_data->sensitive = TRUE;
   action->private_data->visible = TRUE;
@@ -429,6 +439,9 @@ gtk_action_set_property (GObject         *object,
     case PROP_IS_IMPORTANT:
       action->private_data->is_important = g_value_get_boolean (value);
       break;
+    case PROP_HIDE_IF_EMPTY:
+      action->private_data->hide_if_empty = g_value_get_boolean (value);
+      break;
     case PROP_SENSITIVE:
       action->private_data->sensitive = g_value_get_boolean (value);
       break;
@@ -471,6 +484,9 @@ gtk_action_get_property (GObject    *object,
     case PROP_IS_IMPORTANT:
       g_value_set_boolean (value, action->private_data->is_important);
       break;
+    case PROP_HIDE_IF_EMPTY:
+      g_value_set_boolean (value, action->private_data->hide_if_empty);
+      break;
     case PROP_SENSITIVE:
       g_value_set_boolean (value, action->private_data->sensitive);
       break;
@@ -541,7 +557,8 @@ gtk_action_sync_property (GtkAction  *action,
  * <itemizedlist>
  * <listitem><para>if @action is invisible, @proxy is too
  * </para></listitem>
- * <listitem><para>if @empty is %TRUE, hide @proxy unless @action is important
+ * <listitem><para>if @empty is %TRUE, hide @proxy unless the "hide-if-empty" 
+ *   property of @action indicates otherwise
  * </para></listitem>
  * </itemizedlist>
  * 
@@ -552,21 +569,19 @@ _gtk_action_sync_menu_visible (GtkAction *action,
                               GtkWidget *proxy,
                               gboolean   empty)
 {
-  gboolean visible, important;
+  gboolean visible, hide_if_empty;
 
   g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
   g_return_if_fail (action == NULL || GTK_IS_ACTION (action));
   
   if (action == NULL)
     action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
-  
-  g_object_get (G_OBJECT (action), 
-               "visible", &visible, 
-               "is_important", &important,
-               NULL);
+
+  visible = action->private_data->visible;
+  hide_if_empty = action->private_data->hide_if_empty;
 
   g_object_set (G_OBJECT (proxy),
-               "visible", visible && (important || !empty),
+               "visible", visible && !(empty && hide_if_empty),
                NULL);
 }
 
index 5c9a59b7361a22bf5f52a109b8b4fb9e230ea110..53c676a6bbe7b9de2a0625751803fed286d380f0 100644 (file)
@@ -544,9 +544,9 @@ main (int argc, char **argv)
                                entries, n_entries, 
                                NULL);
   action = gtk_action_group_get_action (action_group, "EmptyMenu1Action");
-  g_object_set (G_OBJECT (action), "is_important", TRUE, NULL);
+  g_object_set (G_OBJECT (action), "hide_if_empty", FALSE, NULL);
   action = gtk_action_group_get_action (action_group, "EmptyMenu2Action");
-  g_object_set (G_OBJECT (action), "is_important", FALSE, NULL);
+  g_object_set (G_OBJECT (action), "hide_if_empty", TRUE, NULL);
   gtk_action_group_add_toggle_actions (action_group, 
                                       toggle_entries, n_toggle_entries, 
                                       NULL);